package com.pxmeta.party.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pxmeta.party.entity.ActivityAdAstra;
import com.pxmeta.party.entity.vo.ActivityAdAstraDataStatisticsItemVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ActivityAdAstraMapper extends BaseMapper<ActivityAdAstra> {


    @Select("SELECT\n" +
            "\tCONCAT(\n" +
            "\t\tDATE_FORMAT( t1.create_time, '%m/%d %H:00-' ),\n" +
            "\t\t'',\n" +
            "\tDATE_FORMAT( DATE_ADD( t1.create_time, INTERVAL 1 HOUR ), '%H:00' )) AS time,\n" +
            "\tt1.success_id as id,\n" +
            "\tt2.`name` as name,\n" +
            "\tt2.probability,\n" +
            "\tCOUNT(t1.id) AS count \n" +
            "FROM\n" +
            "\tkt_activity_ad_astra_record t1 left join kt_activity_ad_astra t2 on success_id = t2.id\n" +
            "WHERE\n" +
            "\tt1.success_id = #{successId} \n" +
            "\tAND DATE_FORMAT( t1.create_time, '%Y-%m-%d %H' ) < DATE_FORMAT( NOW(), '%Y-%m-%d %H' ) \n" +
            "\tAND DATE_SUB( NOW(), INTERVAL 10 HOUR )< t1.create_time \n" +
            "GROUP BY\n" +
            "\ttime \n" +
            "ORDER BY\n" +
            "\ttime DESC\n")
    List<ActivityAdAstraDataStatisticsItemVO> getDataStatisticsDetail(@Param("successId") Long successId);
}
